home *** CD-ROM | disk | FTP | other *** search
/ CDUTIL 13 / CDUTIL #13 Julio 1995.iso / windows / acadcom / acrx / sample / dlgtest.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  21.2 KB  |  743 lines

  1. /* Next available MSG number is 21 */
  2. /*
  3.  
  4.    ADS Programmable Dialog Box Test Program for Rx
  5.  
  6.    DLGTEST.CC
  7.  
  8.    Copyright (C) 1994 by Autodesk, Inc.
  9.  
  10.    Permission to use, copy, modify, and distribute this software in 
  11.    object code form for any purpose and without fee is hereby granted, 
  12.    provided that the above copyright notice appears in all copies and 
  13.    that both that copyright notice and the limited warranty and 
  14.    restricted rights notice below appear in all supporting 
  15.    documentation.
  16.  
  17.    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  
  18.    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF 
  19.    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  20.    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE 
  21.    UNINTERRUPTED OR ERROR FREE.
  22.  
  23.    Use, duplication, or disclosure by the U.S. Government is subject to 
  24.    restrictions set forth in FAR 52.227-19 (Commercial Computer 
  25.    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  26.    (Rights in Technical Data and Computer Software), as applicable.
  27.     
  28.    .
  29.  
  30.     Programmable Dialog Box Test Program
  31.  
  32.     CREATED BY:  Ed Becnel, January 1994
  33.  
  34.     Function Entry Points: 
  35.       AcRx::AppRetCode
  36.         acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt);
  37.  
  38.     Exported ADS Functions
  39.         RXSLIDE
  40.     RXDIMEN
  41.     RXSETCOLOR
  42.  
  43.     Modification History:
  44.         Jan 15 1994 - eab - original creation
  45.  
  46.     Notes:
  47.  
  48.      This program is the ADS/Arx counterpart to the LISP test
  49.     program, dlgtest.lsp, and the ADS counterpart, dlgtest.c.  It 
  50.     provides a simple dimensioning dialog invoked with the command 
  51.     "dimen" and a simple color dialog invoked with the command "setcolor".
  52.  
  53.      The purposes of providing this program:
  54.     1) Demonstrate Programmable Dialog Box use with minimum of code
  55.     to sort through
  56.     2) Demonstrate differences between LISP and ADS dialog 
  57.     programming
  58.     3) Use as a starting point to try out new dialog code.
  59.  
  60.      dlgtest uses the file dlgtest.dcl as the DCL (Dialog 
  61.      Control Language) file.
  62.  
  63.     ADS functions are associated with dialog buttons with 
  64.     the ads_action_tile functions.  These functions are called 
  65.     when the user presses buttons during the ads_start_dialog 
  66.     function.
  67.  
  68.     Special tile names (keys): 
  69.     "accept" - Ok button
  70.     "cancel" - Cancel button
  71.  
  72.  
  73. */
  74.  
  75.  
  76. /**************************************************************************/
  77. /*  INCLUDES                                                              */
  78. /**************************************************************************/
  79. #include <stdlib.h>
  80. #include <stdio.h>
  81. #include <string.h>
  82. #include "rxdefs.h"
  83. #include "adslib.h"
  84. #include "adsdlg.h"
  85.  
  86.  
  87. extern "C" {
  88. /****************************************************************************/
  89. /*  LOCALLY DEFINED ENTRY POINT INVOKED BY Arx                               */
  90. /****************************************************************************/
  91. AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt);
  92. }
  93.  
  94. /****************************************************************************/
  95. /*  LOCAL FUNCTION FORWARD DECLARATIONS                                     */
  96. /****************************************************************************/
  97. int viewslide();
  98. int setdimen();
  99. int setcolor();
  100.  
  101. void get_dimvars (ads_hdlg hdlg);
  102. static void set_dimvars (ads_hdlg hdlg);
  103. static void CALLB dimen_ok   (ads_callback_packet *cpkt);
  104. static void CALLB editcol_cb (ads_callback_packet *cpkt);
  105. static void CALLB listcol_cb (ads_callback_packet *cpkt);
  106. static void CALLB help_cb    (ads_callback_packet *cpkt);
  107. static void CALLB cancelcol_cb (ads_callback_packet *cpkt);
  108. static void CALLB viewslide_OK(ads_callback_packet *cpkt);
  109. static void CALLB subdlg_OK(ads_callback_packet *cpkt);
  110. static void CALLB subdlg_handler(ads_callback_packet *);
  111. static void CALLB subdlg_terminate(ads_callback_packet *);
  112. static void CALLB subdlg_term_on_off(ads_callback_packet *cpkt);
  113. void dlg_colortile (ads_hdlg hdlg, char *key, short color, int borderflag);
  114. void dlg_rect (short x, short y, short width, short height, short color);
  115.  
  116. int funcload   (void);
  117. int funcunload (void);
  118. int dofun      (void);
  119.  
  120. /**************************************************************************/
  121. /*  TYPEDEFS                                                              */
  122. /**************************************************************************/
  123. /* ADS Function Table */
  124. typedef struct {
  125.     char    *name;
  126.     int     (*fptr)();
  127. } ftblent;
  128.  
  129. /****************************************************************************/
  130. /*  DEFINES                                                                 */
  131. /****************************************************************************/
  132. #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
  133.  
  134. #ifndef BLACK
  135. #define    BLACK    0
  136. #define    RED      1
  137. #define    YELLOW   2
  138. #define    GREEN    3
  139. #define    CYAN     4
  140. #define    BLUE     5
  141. #define    MAGENTA  6
  142. #define    WHITE    7
  143. #endif
  144.  
  145. #define MAXHEIGHTLEN 4
  146.  
  147. /**************************************************************************/
  148. /*  GLOBAL VARIABLES                                                      */
  149. /**************************************************************************/
  150. /* Table of ADS functions */
  151. ftblent exfun[] = {
  152.             {/*MSG0*/"C:RXSLIDE", viewslide},
  153.         {/*MSG0*/"C:RXDIMEN", setdimen},
  154.         {/*MSG0*/"C:RXSETCOLOR", setcolor}
  155.         };
  156.  
  157. static char *dimbools[] = {
  158.     /*MSG0*/"dimse1", 
  159.     /*MSG0*/"dimse2", 
  160.     /*MSG0*/"dimtih", 
  161.     /*MSG0*/"dimtoh",
  162.     /*MSG0*/"dimtad",
  163.     /*MSG0*/"dimtol", 
  164.     /*MSG0*/"dimlim", 
  165.     /*MSG0*/"dimalt", 
  166.     /*MSG0*/"dimaso",
  167.     /*MSG0*/"dimsho",
  168.     NULL
  169.    };
  170.  
  171. static char *dimreals[] = {
  172.     /*MSG0*/"dimasz", 
  173.     /*MSG0*/"dimtsz", 
  174.     /*MSG0*/"dimtxt", 
  175.     /*MSG0*/"dimcen",
  176.     /*MSG0*/"dimexo",
  177.     /*MSG0*/"dimexe", 
  178.     /*MSG0*/"dimdle", 
  179.     NULL
  180.    };
  181.  
  182. static short color;
  183. static short color_save;
  184. #define CLEN 32
  185. static char colorstr[CLEN+1] = "0";
  186. static char colorstr_save[CLEN+1] = "0";
  187. static int allow_terminate = 0;
  188.  
  189. static char *colorlist[] = {
  190.     /*MSG1*/"black", 
  191.     /*MSG2*/"red", 
  192.     /*MSG3*/"yellow", 
  193.     /*MSG4*/"green", 
  194.     /*MSG5*/"cyan", 
  195.     /*MSG6*/"blue",
  196.     /*MSG7*/"magenta", 
  197.     /*MSG8*/"white"
  198.    };
  199.  
  200. static int dcl_id;
  201.  
  202. /******************************************************************************/
  203. /*.doc funcload(internal) */
  204. /*+
  205.     This function is called to define all function names in the ADS
  206.     function table.  Each named function will be callable from lisp or
  207.     invokable from another ADS application.
  208. -*/
  209. /******************************************************************************/
  210. int
  211. /*FCN*/funcload()
  212. {
  213.     int i;
  214.  
  215.     for (i = 0; i < ELEMENTS(exfun); i++) {
  216.         if (!ads_defun(exfun[i].name, i))
  217.             return RTERROR;
  218.     }
  219.  
  220.     return RTNORM;
  221. }
  222.  
  223. /******************************************************************************/
  224. /*.doc funclunoad(internal) */
  225. /*+
  226.     This function is called to undefine all function names in the ADS
  227.     function table.  Each named function will be removed from the
  228.     AutoLISP hash table.
  229. -*/
  230. /******************************************************************************/
  231. int
  232. /*FCN*/funcunload()
  233. {
  234.     int i;
  235.  
  236.     /* Undefine each function we defined */
  237.  
  238.     for (i = 0; i < ELEMENTS(exfun); i++) {
  239.         ads_undef(exfun[i].name,i);
  240.     }
  241.  
  242.     return RTNORM;
  243. }
  244.  
  245. /******************************************************************************/
  246. /*.doc dofun(internal) */
  247. /*+
  248.     This function is called to invoke the function which has the
  249.     registerd function code that is obtained from  ads_getfuncode.  The
  250.     function will return RTERROR if the function code is invalid, or
  251.     RSERR if the invoked function fails to return RTNORM.  The value
  252.     RSRSLT will be returned if the function code is valid and the
  253.     invoked subroutine returns RTNORM.
  254. -*/
  255. /******************************************************************************/
  256. int
  257. /*FCN*/dofun()
  258. {
  259.     int    val;
  260.     int    rc;
  261.  
  262.     ads_retvoid();
  263.         
  264.     if ((val = ads_getfuncode()) < 0 || val > ELEMENTS(exfun))
  265.         return RTERROR;
  266.  
  267.     rc = (*exfun[val].fptr)();
  268.  
  269.     return ((rc == RTNORM) ? RSRSLT:RSERR);
  270. }
  271.  
  272.  
  273. /* 
  274.  
  275.         VIEWLIDE -- Slide Viewer Dialog
  276.  
  277. */
  278.  
  279. int
  280. /*FCN*/viewslide()
  281. {
  282.     ads_hdlg hdlg;
  283.     int dlg_status;
  284.     short x, y;
  285.     char height_val[MAXHEIGHTLEN];
  286.  
  287.  
  288.     /* Load the dialog file */
  289.     ads_load_dialog(/*MSG0*/"viewslid.dcl", &dcl_id);
  290.     if (dcl_id < 0) {
  291.     ads_printf(/*MSG19*/"Error loading \"viewslid.dcl\"\n");
  292.     return RTERROR;
  293.     }
  294.     /* initialize the viewslide dialog, no default callback function */
  295.     ads_new_dialog(/*MSG0*/"viewslide", dcl_id, (CLIENTFUNC)0, &hdlg);
  296.     if (hdlg == NULL) {
  297.     ads_printf(/*MSG20*/"new_dialog for viewslide failed\n");
  298.     ads_unload_dialog(dcl_id);
  299.     return RTERROR;
  300.     }
  301.  
  302.     /* Update other tiles when one is changed by using callback
  303.        functions */
  304.     ads_action_tile(hdlg, "accept", (CLIENTFUNC)viewslide_OK);
  305.     ads_action_tile(hdlg, "subdlgtest", (CLIENTFUNC)subdlg_handler); 
  306.  
  307.     ads_dimensions_tile(hdlg, "color_whl", &x, &y);
  308.     ads_start_image(hdlg, "color_whl");
  309.     ads_slide_image(0, 0, x, y, "colorwh");
  310.     ads_end_image();
  311.  
  312.     /* Get key */
  313.     ads_get_attr(hdlg, "color_whl", "height", height_val, MAXHEIGHTLEN);
  314.     if (strcmp(height_val, "7") != 0)
  315.     ads_printf("\nValue for color_whl tile's height attribute is incorrect: %s != 7\n", height_val);
  316.     
  317.     /* Hand control over to the dialog until OK is pressed */
  318.     ads_start_dialog(hdlg, &dlg_status);
  319.  
  320.     /* free all memory for dialog */
  321.     ads_unload_dialog(dcl_id);
  322.  
  323.     return RTNORM;
  324. }
  325.  
  326. static void CALLB viewslide_OK(ads_callback_packet *cpkt)
  327. {
  328.     ads_done_dialog(cpkt->dialog, DLGOK);
  329. }
  330.  
  331. static void CALLB subdlg_handler(ads_callback_packet *) 
  332. {
  333.     int dlg_status;
  334.     ads_hdlg sdlg;
  335.  
  336.     /* initialize the viewslide dialog, no default callback function */
  337.     ads_new_dialog(/*MSG0*/"subdlg", dcl_id, (CLIENTFUNC)0, &sdlg);
  338.     if (sdlg == NULL) {
  339.     ads_printf(/*MSG20*/"new_dialog for sub-dialog failed\n");
  340.     return;
  341.     }
  342.        
  343.     /* Update other tiles when one is changed by using callback
  344.        functions */
  345.     ads_action_tile(sdlg, "accept", (CLIENTFUNC)subdlg_OK);
  346.     ads_action_tile(sdlg, "terminate", (CLIENTFUNC)subdlg_terminate);
  347.     ads_action_tile(sdlg, "term_on_off", (CLIENTFUNC)subdlg_term_on_off);
  348.     if (allow_terminate) {
  349.     ads_mode_tile(sdlg, "terminate", MODE_ENABLE);
  350.     ads_set_tile(sdlg, "term_on_off", "1");
  351.     }
  352.     else {
  353.     ads_mode_tile(sdlg, "terminate", MODE_DISABLE);
  354.     ads_set_tile(sdlg, "term_on_off", "0");
  355.     }
  356.        
  357.     /* Hand control over to the dialog until OK is pressed */
  358.     ads_start_dialog(sdlg, &dlg_status);
  359.        
  360.     return;
  361. }
  362.  
  363. static void CALLB subdlg_OK(ads_callback_packet *cpkt)
  364. {
  365.     ads_done_dialog(cpkt->dialog, DLGOK);
  366. }
  367.  
  368. static void CALLB subdlg_terminate(ads_callback_packet *)
  369. {
  370.     ads_term_dialog();
  371. }
  372.  
  373. static void CALLB subdlg_term_on_off(ads_callback_packet *cpkt)
  374. {
  375.     ads_hdlg sdlg = cpkt->dialog;
  376.     char value[TILE_STR_LIMIT];
  377.     
  378.     strcpy(value, cpkt->value);
  379.     if (strcmp(value, "0") == 0) {      /* Disabled */
  380.     ads_mode_tile(sdlg, "terminate", MODE_DISABLE);
  381.     allow_terminate = 0;
  382.     }
  383.     else {
  384.     ads_mode_tile(sdlg, "terminate", MODE_ENABLE);
  385.     allow_terminate = 1;
  386.     }
  387. }
  388.  
  389.  
  390. /* 
  391.  
  392.         DIMEN -- Dimensioning Dialog
  393.  
  394. */
  395.  
  396. /* Position of dialog, centered to start */
  397. static int dimx = -1, 
  398.        dimy = -1; 
  399.  
  400. int
  401. /*FCN*/setdimen()
  402. {
  403.     ads_hdlg hdlg;
  404.     int dlg_status;
  405.     int dcl_id;
  406.  
  407.     ads_load_dialog(/*MSG0*/"dlgtest.dcl", &dcl_id);
  408.     if (dcl_id < 0) {
  409.     ads_printf(/*MSG13*/"Error loading \"dlgtest.dcl\"\n");
  410.     return RTERROR;
  411.     }
  412.     /* Display the "dimensions" dialog */
  413.     ads_new_positioned_dialog(/*MSG14*/"dimensions", dcl_id, 
  414.             (CLIENTFUNC)0, dimx, dimy, &hdlg);
  415.     if (hdlg == NULL) {
  416.     ads_printf(/*MSG15*/"The ads_new_dialog function failed\n");
  417.     ads_unload_dialog(dcl_id);
  418.     return RTERROR;
  419.     }
  420.  
  421.     /* Register dimen_ok function with the OK button */
  422.     ads_action_tile(hdlg, /*MSG0*/"accept", (CLIENTFUNC)dimen_ok);
  423.  
  424.     /* show current values in dialog */
  425.     get_dimvars(hdlg);
  426.  
  427.     /* run the dialog */
  428.     ads_start_dialog(hdlg, &dlg_status);
  429.  
  430.     /* free all memory for dialog */
  431.     ads_unload_dialog(dcl_id);
  432.  
  433.     return RTNORM;
  434. }
  435.  
  436.  
  437. /* DIMEN_OK -- callback function for OK button of dimension dialog.  */
  438.  
  439. static void CALLB
  440. /*FCN*/dimen_ok(ads_callback_packet *cpkt)
  441. {
  442.     /* User pressed OK button to end dialog.  Check modified data
  443.        and send to AutoCAD. */
  444.     set_dimvars(cpkt->dialog);
  445.     ads_done_positioned_dialog(cpkt->dialog, 1, &dimx, &dimy);
  446. }
  447.  
  448.  
  449. /* Show current values in dialog */
  450.  
  451. void
  452. /*FCN*/get_dimvars(ads_hdlg hdlg)
  453. {
  454.     char *bitem;
  455.     char *ritem;
  456.     char **blist = dimbools;
  457.     char **rlist = dimreals;
  458.     char value[80];
  459.     struct resbuf rb;
  460.  
  461.     for ( ; (bitem = *blist) != NULL; ++blist) {
  462.         ads_getvar(bitem, &rb);
  463.         if (rb.restype != RTSHORT) {
  464.             ads_printf(/*MSG17*/"No such AutoCAD variable: %s\n", bitem);
  465.             if (rb.restype == RTSTR)
  466.                 free(rb.resval.rstring);
  467.             continue;
  468.         }
  469.         sprintf(value, "%d", rb.resval.rint);
  470.         ads_set_tile(hdlg, bitem, value);
  471.     }
  472.     for ( ; (ritem = *rlist) != NULL; ++rlist) {
  473.         ads_getvar(ritem, &rb);
  474.         if (rb.restype != RTREAL) {
  475.             ads_printf(/*MSG18*/"No such AutoCAD variable: %s\n", ritem);
  476.             if (rb.restype == RTSTR)
  477.                 free(rb.resval.rstring);
  478.             continue;
  479.         }
  480.         ads_rtos(rb.resval.rreal, -1, -1, value);
  481.         ads_set_tile(hdlg, ritem, value);
  482.     }
  483.     ads_set_tile(hdlg, /*MSG0*/"test_item", /*MSG0*/"test_value");
  484. }
  485.  
  486.  
  487. /* set modified dimension variables in AutoCAD */
  488.  
  489. static void
  490. /*FCN*/set_dimvars(ads_hdlg hdlg)
  491. {
  492.     char *bitem;
  493.     char *ritem;
  494.     char **blist = dimbools;
  495.     char **rlist = dimreals;
  496.     char val[MAX_TILE_STR+1];
  497.     struct resbuf rb;
  498.  
  499.     /* Check all the checkbox tiles for new values */
  500.     for ( ; (bitem = *blist) != NULL; ++blist) {
  501.         /* Get the new value of tiles */
  502.         ads_get_tile(hdlg, bitem, val, MAX_TILE_STR);
  503.  
  504.         rb.restype = RTSHORT;
  505.         rb.resval.rint = atoi(val);
  506.         ads_setvar(bitem, &rb);
  507.     }
  508.     /* Check all the edit box tiles for new values */
  509.     for ( ; (ritem = *rlist) != NULL; ++rlist) {
  510.         /* Get the new value of tiles */
  511.         ads_get_tile(hdlg, ritem, val, MAX_TILE_STR);
  512.         rb.restype = RTREAL;
  513.         ads_distof(val, -1, &rb.resval.rreal);
  514.         ads_setvar(ritem, &rb);
  515.     }
  516.     ads_get_tile(hdlg, /*MSG0*/"test_item", /*MSG0*/"test_value", 50);
  517. }
  518.  
  519.  
  520. /* 
  521.  
  522.         SETCOLOR -- Color Dialog
  523.  
  524. */
  525.  
  526. int
  527. /*FCN*/setcolor()
  528. {
  529.     int idx;
  530.     ads_hdlg hdlg;
  531.     int dlg_status;
  532.     struct resbuf rb;
  533.     char *cptr, *ptr;
  534.     char cname[10];
  535.     int dcl_id;
  536.  
  537.     /* Load the dialog file */
  538.     ads_load_dialog(/*MSG0*/"dlgtest.dcl", &dcl_id);
  539.     if (dcl_id < 0) {
  540.     ads_printf(/*MSG19*/"Error loading \"dlgtest.dcl\"\n");
  541.     return RTERROR;
  542.     }
  543.     /* initialize the setcolor dialog, no default callback function */
  544.     ads_new_dialog(/*MSG0*/"setcolor", dcl_id, (CLIENTFUNC)0, &hdlg);
  545.     if (hdlg == NULL) {
  546.     ads_printf(/*MSG20*/"new_dialog for setcolor failed\n");
  547.     ads_unload_dialog(dcl_id);
  548.     return RTERROR;
  549.     }
  550.     /* Get the current color from AutoCAD */
  551.     ads_getvar(/*MSG0*/"CECOLOR", &rb);
  552.     /* AutoCAD  currently returns  "human readable" colour strings
  553.        like "1 (red)" for the standard colours.  Trim  the  string
  554.        at  the  first space to guarantee we have a valid string to
  555.        restore the colour later.  */
  556.     cptr = rb.resval.rstring;
  557.     ptr = strchr(cptr, ' ');
  558.     if (ptr != NULL)
  559.     *ptr = EOS;
  560.     strcpy(colorstr, cptr);
  561.     /* free(cptr); */    /* Un-comment for production build */
  562.     color = color_save = atoi(colorstr);
  563.     strcpy(colorstr_save, colorstr);
  564.  
  565.     /* Update other tiles when one is changed by using callback
  566.        functions */
  567.     ads_action_tile(hdlg, /*MSG0*/"edit_col", (CLIENTFUNC)editcol_cb);
  568.     ads_action_tile(hdlg, /*MSG0*/"list_col", (CLIENTFUNC)listcol_cb);
  569.     ads_action_tile(hdlg, /*MSG0*/"cancel", (CLIENTFUNC)cancelcol_cb);
  570.  
  571.     ads_action_tile(hdlg, /*MSG0*/"help", (CLIENTFUNC)help_cb);
  572.  
  573.     /* Use the client data pointer to store the key of each tile,
  574.        for convenient access during callbacks.   We could use
  575.        get_attr_string during the callbacks instead. */
  576.     ads_client_data_tile(hdlg, /*MSG0*/"edit_col", /*MSG0*/"edit_col");
  577.     ads_client_data_tile(hdlg, /*MSG0*/"list_col", /*MSG0*/"list_col");
  578.  
  579.     /* Fill list box */
  580.     ads_start_list(hdlg, /*MSG0*/"list_col", LIST_NEW, 0);
  581.     for (idx = 0; idx < 8; ++idx)
  582.     ads_add_list(colorlist[idx]);
  583.     for (idx = 8; idx < 256; ++idx) {
  584.     sprintf(cname, "%d", idx);
  585.     ads_add_list(cname);
  586.     }
  587.     ads_end_list();
  588.  
  589.     /* Show initial values in edit box, list box, and image tile */
  590.     ads_set_tile(hdlg, /*MSG0*/"edit_col", colorstr);
  591.     ads_set_tile(hdlg, /*MSG0*/"list_col", colorstr);
  592.     dlg_colortile(hdlg, /*MSG0*/"show_image", color, TRUE);
  593.  
  594.     /* Hand control over to the dialog until OK or CANCEL is pressed */
  595.     ads_start_dialog(hdlg, &dlg_status);
  596.  
  597.     /* Dialog ended with OK button, "accept"? */
  598.     if (dlg_status == DLGOK) {
  599.     struct resbuf rb;
  600.     rb.restype = RTSTR;
  601.     if (color == 0) {
  602.         rb.resval.rstring = "BYLAYER";
  603.         ads_setvar("cecolor", &rb);
  604.     } else {
  605.         rb.resval.rstring = colorstr;
  606.         ads_setvar("cecolor", &rb);
  607.     }
  608.     }
  609.     /* free all memory for dialog */
  610.     ads_unload_dialog(dcl_id);
  611.  
  612.     return RTNORM;
  613. }
  614.  
  615.  
  616. /* EDITCOL_CB -- ADS callback for color edit box.  */
  617.  
  618. static void CALLB
  619. /*FCN*/editcol_cb(ads_callback_packet *cpkt)
  620. {
  621.     if (cpkt->value == NULL || cpkt->value[0] == EOS) 
  622.     return;
  623.  
  624.     ads_set_tile(cpkt->dialog, /*MSG0*/"list_col", cpkt->value);
  625.     color = atoi(cpkt->value);
  626.     strcpy(colorstr, cpkt->value);
  627.     dlg_colortile(cpkt->dialog, /*MSG0*/"show_image", color, TRUE);
  628. }
  629.  
  630. #define MAXKEYLEN 32
  631.  
  632. /* LISTCOL_CB -- ADS callback for color edit box.  */
  633.  
  634. static void CALLB
  635. /*FCN*/listcol_cb(ads_callback_packet *cpkt)
  636. {
  637.     char akey[MAXKEYLEN];
  638.  
  639.     if (cpkt->value == NULL || cpkt->value[0] == EOS)
  640.     return;
  641.  
  642.     /* Get key */
  643.     ads_get_attr_string(cpkt->tile, /*MSG0*/"key", akey, MAXKEYLEN);
  644.     if (strcmp(akey, "list_col") != 0)
  645.     ads_printf("\nlist_col key is incorrect: %s != list_col\n", akey);
  646.  
  647.     ads_set_tile(cpkt->dialog, /*MSG0*/"edit_col", cpkt->value);
  648.     color = atoi(cpkt->value);
  649.     strcpy(colorstr, cpkt->value);
  650.     dlg_colortile(cpkt->dialog, /*MSG0*/"show_image", color, TRUE);
  651. }
  652.  
  653. /*HELP_CB -- ADS callback for help button.  */
  654.  
  655. static void CALLB
  656. /*FCN*/help_cb(ads_callback_packet *cpkt)
  657. {
  658.     /* request main Acad help, just to show you can do it. */
  659.     ads_help(NULL, NULL, 0);
  660. }
  661.  
  662. /* CANCELCOL_CB -- ADS callback for color edit box - cancel pressed.  */
  663.  
  664. static void CALLB
  665. /*FCN*/cancelcol_cb(ads_callback_packet *cpkt)
  666. {
  667.     color = color_save;
  668.     strcpy(colorstr, colorstr_save);
  669.     dlg_colortile(cpkt->dialog, /*MSG0*/"show_image", color, TRUE);
  670. }
  671.  
  672. /* DLG_COLORTILE -- Color a tile.  "dialog" can be NULL to use the
  673.             current dialog.  Values for "color" may be 0 to
  674.             255.  "color" may be one of the defines in
  675.             colours.h, such as RED.   Draws border if
  676.             borderflag is TRUE. */
  677.  
  678. void
  679. /*FCN*/dlg_colortile(ads_hdlg hdlg, char *key, short color, int borderflag)
  680. {
  681.     short width, height;
  682.  
  683.     ads_dimensions_tile(hdlg, key, &width, &height);
  684.     ads_start_image(hdlg, key);
  685.     ads_fill_image(0, 0, width, height, color);
  686.  
  687.     if (borderflag) {
  688.     /* Put border around color */
  689.     dlg_rect(0, 0, width, height, WHITE);
  690.     }
  691.     ads_end_image();
  692. }
  693.  
  694.  
  695.  
  696. /* DLG_RECT -- Draw a rectangle in an image tile.  Use tile dimensions
  697.            to draw border around tile.  Assumes start_image
  698.            has been called. */
  699.  
  700. void
  701. /*FCN*/dlg_rect(short x, short y, short width, short height, short color)
  702. {
  703.     short x2, y2;
  704.  
  705.     x2 = x + width - 1;
  706.     y2 = y + height - 1;
  707.     ads_vector_image(x,  y,  x,  y2, color);
  708.     ads_vector_image(x,  y2, x2, y2, color);
  709.     ads_vector_image(x2, y2, x2, y,  color);
  710.     ads_vector_image(x2, y,  x,  y,  color);
  711. }
  712.  
  713.  
  714. /* =================== Arx Module Interface Functions ================ */
  715.  
  716. AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* ptr) {
  717.  
  718.     if (ptr != NULL) {
  719.         // We have been handed some kind of object
  720.         // but we aren't going to do anything with it.
  721.     }
  722.  
  723.     switch(msg) {
  724.     case AcRx::kInitAppMsg:
  725.         ads_printf(/*MSG10*/"Functions: 1-rxdimen 2-rxsetcolor 3-rxslide.\n");
  726.         break;
  727.         case AcRx::kInvkSubrMsg:
  728.             dofun();
  729.             break;
  730.         case AcRx::kLoadADSMsg:
  731.             funcload();
  732.             break;
  733.         case AcRx::kUnloadADSMsg:
  734.             funcunload();
  735.             ads_printf(/*MSG2*/"Unloading.\n");
  736.             break;
  737.     case AcRx::kUnloadAppMsg:
  738.         default:
  739.         break;
  740.     }
  741.     return AcRx::kRetOK;
  742. }
  743.